package club.hicode.daydayup.rabbitmq.direct;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import static club.hicode.daydayup.rabbitmq.MQConst.*;

/**
 * RabbitMQ 上下文配置类
 *
 * @author Liu Chunfu
 * @date 2018-05-08 上午9:26
 **/
@Component
public class RabbitMQDirectConfig {


    ///////  Direct Queue    ///////

    /**
     * Direct 模式的 Queue
     *
     * @return Direct Queue
     */
    @Bean
    public Queue directQueue() {
        return new Queue(DIRECT_QUEUE, true);
    }

    ///////  Topic Queue    ///////
    /*需要3个元素，topicExchange,topicQueue,topicBinding*/

    @Bean
    public Queue topicQueue() {
        return new Queue(TOPIC_QUEUE);
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(TOPIC_EXCHANGE);
    }

    @Bean
    public Binding topicBinding(Queue topicQueue, TopicExchange topicExchange) {
        //bind to with 3元素
        return BindingBuilder.bind(topicQueue).to(topicExchange).with(TOPIC_KEY);
    }


}
